package org.zachary.agent.infrastructure.repository;

import org.springframework.stereotype.Repository;
import org.zachary.agent.domain.aggregate_model.user_credit.UserCredit;
import org.zachary.agent.domain.repository.UserCreditRepository;

import java.util.Optional;

@Repository
public class JpaUserCreditRepository implements UserCreditRepository {
    private final SpringDataUserCreditRepository jpaRepo;

    public JpaUserCreditRepository(SpringDataUserCreditRepository jpaRepo) {
        this.jpaRepo = jpaRepo;
    }


    @Override
    public void init(UserCredit userCredit) {
        jpaRepo.save(userCredit);
    }

    @Override
    public int update(int id, UserCredit userCredit) {
        jpaRepo.updateById(id,userCredit);
        return userCredit.getCreditScore();
    }

    @Override
    public Optional<UserCredit> findById(Integer id) {
        return jpaRepo.findById(id);
    }

    @Override
    public void setInfoPassed(Integer userId) {
        jpaRepo.setStatusToPassed(userId);
    }

    @Override
    public void setInfoNotPassed(Integer userId) {
        jpaRepo.setStatusToNotPassed(userId);
    }

    @Override
    public void setInfoInImprovement(Integer userId) {
        jpaRepo.setInfoInImproving(userId);
    }


}
